<template>
  <div class="app-container">
    <!-- 基本信息 -->
    <div class="titleLineGreen">基本信息</div>
    <div class="info flex">
      <el-image
        class="info_avatar"
        :src="
          info.avatar ? info.avatar : require('@/assets/images/head_img.png')
        "
        :preview-src-list="[info.avatar]"
      ></el-image>
      <div class="info_right">
        <!-- 教师信息 -->
        <div class="info_teacherinfos">
          <div class="flex info_teacherinfo_line1">
            <div class="info_teacherinfo_line_item flex">
              <el-tooltip
                class="item"
                effect="dark"
                :content="info.name"
                placement="top-start"
              >
                <div class="info_teacherinfo_line_item_nickname overtxt">
                  {{ info.name }}
                </div>
              </el-tooltip>

              <img
                v-if="info.sex == 1"
                class="sex"
                src="@/assets/images/sex_women.png"
                alt=""
              />
              <img
                v-else
                class="sex"
                src="@/assets/images/sex_man.png"
                alt=""
              />
            </div>
            <el-tooltip
              class="item"
              effect="dark"
              :content="info.branch_name"
              placement="top-start"
            >
              <div class="info_teacherinfo_line_item overtxt">
                学院: {{ info.branch_name ? info.branch_name : "--" }}
              </div>
            </el-tooltip>

            <div class="info_teacherinfo_line_item overtxt">
              学号: {{ info.student_num ? info.student_num : "--" }}
            </div>
          </div>
          <div class="flex info_teacherinfo_line2">
            <div class="info_teacherinfo_line_item overtxt">微信号: --</div>
            <div class="info_teacherinfo_line_item overtxt">
              身份证: {{ info.id_card ? info.id_card : "--" }}
            </div>
            <div class="info_teacherinfo_line_item overtxt">
              手机号: {{ info.tel ? info.tel : "--" }}
            </div>
          </div>
        </div>
        <!-- 数据卡片 -->
        <div class="info_dataCards flex">
          <div class="info_dataCard" style="width: 412px; margin: 0 0 0 0px">
            <!-- 数据卡片的顶行 -->
            <div class="info_dataCard_topLine flex">
              <div
                class="info_dataCard_topLine_point"
                style="background: rgba(67, 218, 43, 1)"
              ></div>
              <div class="info_dataCard_topLine_lable">学分情况</div>
            </div>
            <!-- 数据卡片数据行 -->
            <div class="info_dataCard_dateLine info_dataCard_dateLine1 flex">
              <div class="info_dataCard_dateLine_item">
                <div class="info_dataCard_dateLine_item_lable">必修</div>
                <div
                  class="info_dataCard_dateLine_item_value"
                  style="color: rgba(40, 178, 139, 1) !important"
                >
                  {{ info.compulsory_credit
                  }}<span>/{{ info.needCompulsoryCredit }}</span>
                </div>
              </div>
              <div class="info_dataCard_dateLine_item">
                <div class="info_dataCard_dateLine_item_lable">选修</div>
                <div
                  class="info_dataCard_dateLine_item_value"
                  style="color: rgba(44, 172, 255, 1) !important"
                >
                  {{ info.optional_credit
                  }}<span>/{{ info.needOptionalCredit }}</span>
                </div>
              </div>
              <div class="info_dataCard_dateLine_item">
                <div class="info_dataCard_dateLine_item_lable">考证</div>
                <div
                  class="info_dataCard_dateLine_item_value"
                  style="color: rgba(150, 73, 228, 1) !important"
                >
                  {{ info.research_credit
                  }}<span>/{{ info.needCompetitionCredit }}</span>
                </div>
              </div>
              <div class="info_dataCard_dateLine_item">
                <div class="info_dataCard_dateLine_item_lable">工学</div>
                <div
                  class="info_dataCard_dateLine_item_value"
                  style="color: rgba(239, 125, 0, 1) !important"
                >
                  {{ info.engineering_credit
                  }}<span>/{{ info.needEngineeringCredit }}</span>
                </div>
              </div>
            </div>
          </div>
          <div class="info_dataCard" style="width: 500px; margin: 0 0 0 24px">
            <!-- 数据卡片的顶行 -->
            <div class="info_dataCard_topLine flex">
              <div
                class="info_dataCard_topLine_point"
                style="background: rgba(44, 172, 255, 1)"
              ></div>
              <div class="info_dataCard_topLine_lable">
                学习数据 <span>(本学期/历史)</span>
              </div>
            </div>
            <!-- 数据卡片数据行 -->
            <div class="info_dataCard_dateLine info_dataCard_dateLine2 flex">
              <div class="info_dataCard_dateLine_item">
                <div class="info_dataCard_dateLine_item_lable">平均成绩</div>
                <div class="info_dataCard_dateLine_item_value">
                  {{ avgScore || avgScore == 0 ? avgScore.toFixed(2) : "--"
                  }}<span v-if="studyData && studyData.hisAvgScore"
                    >/{{ studyData.hisAvgScore.toFixed(2) }}</span
                  >
                </div>
              </div>
              <div class="info_dataCard_dateLine_item">
                <div class="info_dataCard_dateLine_item_lable">选学步骤</div>
                <div class="info_dataCard_dateLine_item_value">
                  {{
                    studyData && studyData.chooseNum
                      ? studyData.chooseNum
                      : "0"
                  }}<span></span>
                </div>
              </div>
              <div class="info_dataCard_dateLine_item">
                <div class="info_dataCard_dateLine_item_lable">优秀率</div>
                <div class="info_dataCard_dateLine_item_value">
                  {{
                    studyData && studyData.goodPer
                      ? studyData.goodPer + "%"
                      : "0%"
                  }}<span></span>
                </div>
              </div>
              <div class="info_dataCard_dateLine_item">
                <div class="info_dataCard_dateLine_item_lable">重修课程数</div>
                <div class="info_dataCard_dateLine_item_value">
                  {{
                    studyData && studyData.resatrtNum
                      ? studyData.resatrtNum
                      : "0"
                  }}<span v-if="studyData && studyData.hisResatrtNum"
                    >/{{ studyData.hisResatrtNum }}</span
                  >
                </div>
              </div>
              <div class="info_dataCard_dateLine_item">
                <div class="info_dataCard_dateLine_item_lable">补考次数</div>
                <div class="info_dataCard_dateLine_item_value">
                  {{ studyData && studyData.applyNum ? studyData.applyNum : "0"
                  }}<span v-if="studyData && studyData.hisApplyNum"
                    >/{{ studyData.hisApplyNum }}</span
                  >
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- 学习记录 -->
    <div class="titleLineGreen" style="margin-top: 40px">学习记录</div>
    <el-form
      style="margin-top: 20px"
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="课程" prop="courseName">
        <el-input
          v-input-restrict
          v-model="queryParams.courseName"
          placeholder="请输入课程名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工作站" prop="workstationName">
        <el-input
          v-input-restrict
          v-model="queryParams.workstationName"
          placeholder="请输入工作站名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学分类型" prop="type">
        <el-select
          filterable
          v-model="queryParams.type"
          placeholder="请选择学分类型"
          clearable
          style="width: 100px"
        >
          <el-option
            v-for="dict in dict.type.sys_course_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          v-preventReClick
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button
          v-preventReClick
          icon="el-icon-refresh"
          size="mini"
          @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <el-table
      v-loading="loading"
      :data="postList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column
        show-overflow-tooltip
        :label="`${$courseName ? $courseName : '课程'}名称`"
        align="center"
        prop="course_name"
      />
      <el-table-column
        show-overflow-tooltip
        :label="`${$workstationName ? $workstationName : '工作站'}名称`"
        align="center"
        prop="workstation_name"
      >
        <template slot-scope="scope">
          <div>
            {{ scope.row.workstation_name ? scope.row.workstation_name : "--" }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="类型" align="center" prop="type">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.sys_course_type"
            :value="scope.row.type"
          />
        </template>
      </el-table-column>

      <el-table-column sortable label="学分" align="center" prop="credit" />

      <el-table-column
        sortable
        label="学习时间(h)"
        align="center"
        prop="study_time"
      >
        <template slot-scope="scope">
          <div>
            {{
              scope.row.study_time
                ? (scope.row.study_time / 60 / 60).toFixed(2)
                : "--"
            }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="课程状态" align="center" prop="study_status">
        <template slot-scope="scope">
          <el-tag type="danger" v-if="scope.row.study_status == -1"
            >未通过</el-tag
          >
          <el-tag type="success" v-if="scope.row.study_status == 2"
            >已学习</el-tag
          >
          <el-tag type="info" v-if="scope.row.study_status == 0">未开始</el-tag>
          <el-tag v-if="scope.row.study_status == 1">学习中</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        sortable
        label="成绩(百分制)"
        align="center"
        prop="avgScore"
      >
        <template slot-scope="scope">
          <div>
            {{
              scope.row.avgScore || scope.row.avgScore == 0
                ? scope.row.avgScore
                : "--"
            }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="教师评价" align="center" prop="stu_level"
        ><template slot-scope="scope">
          <div v-if="scope.row.stu_level == 1">优秀</div>
          <div v-else-if="scope.row.stu_level == 2">良好</div>
          <div v-else-if="scope.row.stu_level == 3">及格</div>
          <div v-else-if="scope.row.stu_level == 4">不及格</div>
          <div v-else>--</div>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            v-preventReClick
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleDetail(scope.row, scope.$index)"
            >详情</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    /> -->
    <!-- 添加或修改岗位对话框 -->
    <el-dialog
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :title="title"
      :visible.sync="open"
      width="500px"
      append-to-body
    >
      <el-form
        @submit.native.prevent
        ref="form"
        :model="form"
        :rules="rules"
        label-width="80px"
      >
        <el-form-item label="岗位名称" prop="postName">
          <el-input
          v-input-restrict v-model="form.postName" placeholder="请输入岗位名称" />
        </el-form-item>
        <el-form-item label="岗位编码" prop="postCode">
          <el-input
          v-input-restrict v-model="form.postCode" placeholder="请输入编码名称" />
        </el-form-item>
        <el-form-item label="岗位顺序" prop="postSort">
          <el-input
          v-input-restrict-number
            v-model="form.postSort"
            controls-position="right"
            :min="0"
          />
        </el-form-item>
        <el-form-item label="岗位状态" prop="status">
          <el-radio-group v-model="form.status">
            <el-radio
              v-for="dict in dict.type.sys_normal_disable"
              :key="dict.value"
              :label="dict.value"
              >{{ dict.label }}</el-radio
            >
          </el-radio-group>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input
          v-input-restrict
            v-model="form.remark"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button v-preventReClick @click="cancel">取 消</el-button>
        <el-button v-preventReClick type="primary" @click="submitForm"
          >确 定</el-button
        >
      </div>
    </el-dialog>
    <studentGradeDetail
      :open.sync="studentGradeDetailOpen"
      :id="studentGradeDetailId"
      :index="studentGradeDetailIndex"
      :list="studentGradeDetailList"
    ></studentGradeDetail>
  </div>
</template>

<script>
import studentGradeDetail from "./components/studentGradeDetail";
import {
  listPost,
  getPost,
  delPost,
  addPost,
  updatePost,
} from "@/api/system/post";
import {
  studentStudyData,
  studentCourses,
} from "@/api/schoolOrganization/student";
export default {
  name: "Post",
  components: {
    studentGradeDetail,
  },
  dicts: ["sys_course_type"],
  data() {
    return {
      avgScore: undefined,
      // 学生详情组件参数
      studentGradeDetailOpen: false,
      studentGradeDetailId: "",
      studentGradeDetailIndex: "",
      studentGradeDetailList: [],
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 岗位表格数据
      postList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 9999,
        courseName: undefined,
        workstationName: undefined,
        type: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        postName: [
          { required: true, message: "岗位名称不能为空", trigger: "blur" },
        ],
        postCode: [
          { required: true, message: "岗位编码不能为空", trigger: "blur" },
        ],
        postSort: [
          { required: true, message: "岗位顺序不能为空", trigger: "blur" },
        ],
      },
      //   学生信息
      info: {},
      studyData: {},
    };
  },
  created() {
    this.getList();
    this.getInfo();
  },
  methods: {
    /* 获取成绩详情 */
    handleDetail(row, index) {
      this.studentGradeDetailOpen = true;
      // 此处为获取ccCourseStuI
      this.studentGradeDetailId = row.id;
      this.studentGradeDetailIndex = index;
      this.studentGradeDetailList = this.postList;
    },
    /* 查询学生详细信息 */
    async getInfo() {
      let res = await studentStudyData(this.$route.query.studentId);
      this.info = res.data.baseInfo;
      this.studyData = res.data.studyData;
    },

    /** 查询岗位列表 */
    getList() {
      this.loading = true;
      this.queryParams.studentId = this.$route.query.studentId;
      studentCourses(this.queryParams).then((response) => {
        let avglist = [...response.data];
        // 计算列表成绩列的平均成绩,如果成绩为零的数据行不进入计算
        avglist = avglist.filter((item) => {
          return item.avgScore || item.avgScore == 0;
        });
        if (avglist.length > 0) {
          this.avgScore =
            avglist.reduce((pre, cur) => {
              return pre + cur.avgScore;
            }, 0) / avglist.length;
        }

        this.postList = response.data;

        // this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        pageNum: 1,
        pageSize: 9999,
        courseName: undefined,
        workstationName: undefined,
        type: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.postId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加岗位";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const postId = row.postId || this.ids;
      getPost(postId).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改岗位";
      });
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.postId != undefined) {
            updatePost(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPost(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const postIds = row.postId || this.ids;
      this.$modal
        .confirm('确定删除岗位编号为"' + postIds + '"的数据项？')
        .then(function () {
          return delPost(postIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/post/export",
        {
          ...this.queryParams,
        },
        `post_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
<style lang="scss" scoped>
.info.flex {
  margin: 23px 0 0 0;
  .info_avatar {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    box-sizing: border-box;
    border: 1px solid rgba(229, 229, 229, 1);
    margin: 0 24px 0 10px;
  }

  .info_right {
    .info_teacherinfos {
      .info_teacherinfo_line_item {
        box-sizing: border-box;
        padding-right: 25px;
        width: 276px;
        font-size: 14px;
        font-weight: 400;
        line-height: 20px;
        color: rgba(96, 98, 102, 1);
        .info_teacherinfo_line_item_nickname {
          font-size: 18px;
          font-weight: 600;
          line-height: 20px;
          color: rgba(51, 51, 51, 1);
          max-width: 227px;
        }
        .sex {
          margin: 5px 0 0 5px;
          width: 12px;
          height: 12px;
        }
      }
      .info_teacherinfo_line1 {
        margin-top: 3px;
      }
      .info_teacherinfo_line2 {
        margin-top: 15px;
      }
    }

    .info_dataCards {
      margin-top: 22px;
      .info_dataCard {
        height: 112px;
        border-radius: 8px;
        background: rgba(255, 255, 255, 1);
        box-shadow: 0px 0px 12px rgba(99, 99, 99, 0.14);
        box-sizing: border-box;
        padding: 16px 0 0 20px;
        .info_dataCard_topLine.flex {
          .info_dataCard_topLine_point {
            margin: 5px 8px 0 0;
            width: 10px;
            height: 10px;
            border-radius: 5px;
          }
          .info_dataCard_topLine_lable {
            font-size: 14px;
            font-weight: 600;
            line-height: 20px;
            color: rgba(51, 51, 51, 1);
            span {
              margin: 4px 0 0 0;
              font-size: 10px;
              font-weight: 400;
              line-height: 14px;
              color: rgba(51, 51, 51, 1);
            }
          }
        }
        .info_dataCard_dateLine2 {
          .info_dataCard_dateLine_item:last-of-type {
            width: 60px !important;
          }
        }
        .info_dataCard_dateLine1 {
          .info_dataCard_dateLine_item:last-of-type {
            width: 92px !important;
          }
        }
        .info_dataCard_dateLine.flex {
          margin-top: 20px;
          .info_dataCard_dateLine_item {
            width: 100px;
            .info_dataCard_dateLine_item_lable {
              font-size: 12px;
              font-weight: 400;
              line-height: 17px;
              color: rgba(153, 153, 153, 1);
            }

            .info_dataCard_dateLine_item_value {
              margin-top: 4px;
              font-size: 18px;
              font-weight: 600;
              line-height: 25px;
              color: rgba(238, 62, 62, 1);
              span {
                margin: 4px 0 0 0;
                font-size: 12px;
                font-weight: 400;
                line-height: 16px;
                color: rgba(51, 51, 51, 1);
              }
            }
          }
        }
      }
    }
  }
}
</style>
